<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Db;

class Produce extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';
    protected $userid = '';
    protected $group = [];//组别
    protected $batch = [];//批次
    protected $userstatus = '';//当前登录用户身份


    public function _initialize()
    {
        // $this->userid = session("users.id");
        $this->userid = 1;
        $userinfo = Db::name("app_users")->find($this->userid);
        //
        $this->userstatus = $userinfo['app_status'];
        $this->group = Db::name("pro_group")->select();
        $this->batch = Db::name("pro_batch")->select();

        $this->assign("group", $this->group);
        $this->assign("batch", $this->batch);
    }

    //加光列表
    public function light(){
        $id = $this->userid;
        $list = Db::name("pro_light")
        ->alias('a')
        ->join("pro_group b","a.group_id = b.id")
        ->join("pro_batch c","a.batch_id = c.id")
        ->where(['user_id' => $id])
        ->field("a.*,b.group_name, c.name as batch_name")
        ->select();

        $this->assign("list", $list);
        return $this->view->fetch();
    }

    //配种操作
    public function breed(){
        $id = $this->userid;
        $list = Db::name("pro_breed")
        ->alias('a')
        ->join("pro_group b","a.group_id = b.id")
        ->join("pro_batch c","a.batch_id = c.id")
        ->where(['user_id' => $id])
        ->field("a.*,b.group_name, c.name as batch_name")
        ->select();

        $this->assign("list", $list);
        return $this->view->fetch();
    }

    //摸胎操作
    public function touch(){
        $id = $this->userid;
        $list = Db::name("pro_touch")
        ->alias('a')
        ->join("pro_group b","a.group_id = b.id")
        ->join("pro_batch c","a.batch_id = c.id")
        ->where(['user_id' => $id])
        ->field("a.*,b.group_name, c.name as batch_name")
        ->select();

        $this->assign("list", $list);
        return $this->view->fetch();
    }


    //接产操作
    public function deliver(){
        $id = $this->userid;
        $list = Db::name("pro_deliver")
        ->alias('a')
        ->join("pro_group b","a.group_id = b.id")
        ->join("pro_batch c","a.batch_id = c.id")
        ->where(['user_id' => $id])
        ->field("a.*,b.group_name, c.name as batch_name")
        ->select();

        $this->assign("list", $list);
        return $this->view->fetch();
    }


    //选留操作
    public function select(){
        $id = $this->userid;
        $list = Db::name("pro_select")
        ->alias('a')
        ->join("pro_group b","a.group_id = b.id")
        ->join("pro_batch c","a.batch_id = c.id")
        ->where(['user_id' => $id])
        ->field("a.*,b.group_name, c.name as batch_name")
        ->select();

        $this->assign("list", $list);
        return $this->view->fetch();
    }

    //补奶操作
    public function recoil(){
        $id = $this->userid;
        $list = Db::name("pro_recoil")
        ->alias('a')
        ->join("pro_group b","a.group_id = b.id")
        ->join("pro_batch c","a.batch_id = c.id")
        ->where(['user_id' => $id])
        ->field("a.*,b.group_name, c.name as batch_name")
        ->select();

        $this->assign("list", $list);
        return $this->view->fetch();
    }


    //断奶操作
    public function wean(){
        $id = $this->userid;
        $list = Db::name("pro_wean")
        ->alias('a')
        ->join("pro_group b","a.group_id = b.id")
        ->join("pro_batch c","a.batch_id = c.id")
        ->where(['user_id' => $id])
        ->field("a.*,b.group_name, c.name as batch_name")
        ->select();

        $this->assign("list", $list);
        return $this->view->fetch();
    }


    //断奶预防
    public function wean_pre(){
        $id = $this->userid;
        $list = Db::name("pro_wean_pre")
        ->alias('a')
        ->join("pro_group b","a.group_id = b.id")
        ->join("pro_batch c","a.batch_id = c.id")
        ->where(['user_id' => $id])
        ->field("a.*,b.group_name, c.name as batch_name")
        ->select();

        $this->assign("list", $list);
        return $this->view->fetch();
    }


    //消毒冲舍
    public function disinfect(){
        $id = $this->userid;
        $list = Db::name("pro_disinfect")
        ->alias('a')
        ->join("pro_group b","a.group_id = b.id")
        ->join("disi_type c","a.dis_id = c.id")//消毒类型
        ->where(['user_id' => $id])
        ->field("a.*,b.group_name, c.type as disi_type")
        ->select();

        $this->assign("list", $list);
        return $this->view->fetch();
    }


    //打耳号
    public function ears(){
        $id = $this->userid;
        $list = Db::name("pro_ears_num")
        ->alias('a')
        ->join("pro_group b","a.group_id = b.id")
        ->join("pro_batch c","a.batch_id = c.id")
        ->where(['user_id' => $id])
        ->field("a.*,b.group_name, c.name as batch_name")
        ->select();

        $this->assign("list", $list);
        return $this->view->fetch();
    }


    //称重操作
    public function weigh(){
        $id = $this->userid;
        $list = Db::name("pro_weigh")
        ->alias('a')
        ->join("pro_group b","a.group_id = b.id")
        ->join("pro_batch c","a.batch_id = c.id")
        ->where(['user_id' => $id])
        ->field("a.*,b.group_name, c.name as batch_name")
        ->select();

        $this->assign("list", $list);
        return $this->view->fetch();
    }


    //出栏操作
    public function out(){
        $id = $this->userid;
        $list = Db::name("pro_out")
        ->alias('a')
        ->join("pro_group b","a.group_id = b.id")
        ->join("pro_batch c","a.batch_id = c.id")
        ->where(['user_id' => $id])
        ->field("a.*,b.group_name, c.name as batch_name")
        ->select();

        $this->assign("list", $list);
        return $this->view->fetch();
    }


    //分公母
    public function sex(){
        $id = $this->userid;
        $list = Db::name("pro_sex")
        ->alias('a')
        ->join("pro_group b","a.group_id = b.id")
        ->join("pro_batch c","a.batch_id = c.id")
        ->where(['user_id' => $id])
        ->field("a.*,b.group_name, c.name as batch_name")
        ->select();

        $this->assign("list", $list);
        return $this->view->fetch();
    }

    



}
